﻿CREATE TABLE [dbo].[Account] (
    [AccountId]                 UNIQUEIDENTIFIER NOT NULL,
    [AccountCategoryCode]       INT              NULL,
    [CustomerSizeCode]          INT              NULL,
    [CustomerTypeCode]          INT              NULL,
    [AccountRatingCode]         INT              NULL,
    [IndustryCode]              INT              NULL,
    [AccountClassificationCode] INT              NULL,
    [BusinessTypeCode]          INT              NULL,
    [PaymentTermsCode]          INT              NULL,
    [OriginatingLeadId]         UNIQUEIDENTIFIER NULL,
    [PrimaryContactId]          UNIQUEIDENTIFIER NULL,
    [Name]                      NVARCHAR (160)   NULL,
    [AccountNumber]             NVARCHAR (20)    NULL,
    [Revenue]                   MONEY            NULL,
    [NumberOfEmployees]         INT              NULL,
    [Country]                   NVARCHAR (100)   NULL,
    [City]                      NVARCHAR (100)   NULL,
    [Description]               NVARCHAR (MAX)   NULL,
    [SIC]                       VARCHAR (20)     NULL,
    [TickerSymbol]              NVARCHAR (10)    NULL,
    [OwnershipCode]             INT              NULL,
    [WebSiteURL]                NVARCHAR (200)   NULL,
    [EMailAddress1]             NVARCHAR (100)   NULL,
    [EMailAddress2]             NVARCHAR (100)   NULL,
    [EMailAddress3]             NVARCHAR (100)   NULL,
    [Telephone1]                NVARCHAR (50)    NULL,
    [Telephone2]                NVARCHAR (50)    NULL,
    [Telephone3]                NVARCHAR (50)    NULL,
    [CreatedOn]                 DATETIME         NULL,
    [CreatedById]               UNIQUEIDENTIFIER NULL,
    [ModifiedOn]                DATETIME         NULL,
    [ModifiedById]              UNIQUEIDENTIFIER NULL,
    [VersionNumber]             ROWVERSION       NULL,
    [ParentAccountId]           UNIQUEIDENTIFIER NULL,
    [StatusCode]                INT              NULL,
    [OwnerId]                   UNIQUEIDENTIFIER NOT NULL,
    [IsDeleted]                 BIT              CONSTRAINT [DF_Account_IsDeleted] DEFAULT ((0)) NOT NULL,
    [CountryCode]               INT              NULL,
    [DepartmentId]              UNIQUEIDENTIFIER NULL,
    CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED ([AccountId] ASC),
    CONSTRAINT [FK_Account_Contact] FOREIGN KEY ([PrimaryContactId]) REFERENCES [dbo].[Contact] ([ContactId]),
    CONSTRAINT [FK_Account_Department] FOREIGN KEY ([DepartmentId]) REFERENCES [dbo].[Department] ([DepartmentId]),
    CONSTRAINT [FK_Account_Lead] FOREIGN KEY ([OriginatingLeadId]) REFERENCES [dbo].[Lead] ([LeadId]),
    CONSTRAINT [FK_Account_User] FOREIGN KEY ([OwnerId]) REFERENCES [dbo].[User] ([UserId]),
    CONSTRAINT [FK_Account_User_CreatedBy] FOREIGN KEY ([CreatedById]) REFERENCES [dbo].[User] ([UserId]),
    CONSTRAINT [FK_Account_User_ModifiedBy] FOREIGN KEY ([ModifiedById]) REFERENCES [dbo].[User] ([UserId])
);

